package it.polimi.traveldream.web.beans;

import java.util.List;

import it.polimi.traveldream.ejb.acquistomanagement.AcquistoDTO;
import it.polimi.traveldream.ejb.acquistomanagement.AcquistoMgr;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;


@ManagedBean (name="acquistoBean")
@ViewScoped
public class AcquistoBean {
	
	@EJB
	private AcquistoMgr acquistoMgr;

	private AcquistoDTO nuovoAcquisto;
	
	private List<?> result;

	public AcquistoBean(){
		nuovoAcquisto = new AcquistoDTO();
	}
	
	public String acquista(int idPacchetto){
		//DEBUG ONLY
		System.out.println(idPacchetto);
		//
		//nuovoAcquisto.setPrezzo(pacchetto.getPrezzo()*nuovoAcquisto.getNumPosti());
		acquistoMgr.save(nuovoAcquisto,idPacchetto);
		return "users/index.xhtml?faces-redirect=true";
	}

	public String findByUser(){
		result = acquistoMgr.findByUser();
		return "carrello?faces-redirect=true";
	}
	
	public AcquistoMgr getAcquistoMgr() {
		return acquistoMgr;
	}

	public void setAcquistoMgr(AcquistoMgr acquistoMgr) {
		this.acquistoMgr = acquistoMgr;
	}

	public AcquistoDTO getNuovoAcquisto() {
		return nuovoAcquisto;
	}

	public void setNuovoAcquisto(AcquistoDTO nuovoAcquisto) {
		this.nuovoAcquisto = nuovoAcquisto;
	}

	public List<?> getRisultatoRicerca() {
		return result;
	}

	public void setRisultatoRicerca(List<?> risultatoRicerca) {
		this.result = risultatoRicerca;
	}

	public List<?> getResult() {
		return result;
	}

	public void setResult(List<?> result) {
		this.result = result;
	}
	
	

}
